//
//  PCAccountManager.m
//  PromotionCode
//
//  Created by uuu9 on 2017/11/16.
//  Copyright © 2017年 My. All rights reserved.
//

#import "PCAccountManager.h"
#import "PCAccountModel.h"
#import "PCMarketingCodeModel.h"
#import "PCPointsListModel.h"
#import "PCTuiguangModel.h"
#import "PCTuiguangListModel.h"

@implementation PCAccountManager

+ (void)getAccountWithUserid:(NSString *)userid andSession:(NSString *)session andCompletionHandle:(void (^)(AccountModel *model, NSError *))complete{
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetAccount]
    parameters:[NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session]
completionHandler:^(id responseObj, NSError *error) {
    PCAccountModel *model = [PCAccountModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model.output,error);
}];
}

/*
 post提交参数:用户唯一id userid
 手机号 phone
 手机验证码 code
 */
+ (void)bindWithUserid:(NSString *)userid andSession:(NSString *)session andPhone:(NSString *)phone andCode:(NSString *)code andCompletionHandle:(void (^)(AccountModel *model, NSError *))complete{
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kBindPhone]
           parameters:[NSString stringWithFormat:@"userid=%@&sessionid=%@&phone=%@&code=%@",userid,session,phone,code]
    completionHandler:^(id responseObj, NSError *error) {
        PCAccountModel *model = [PCAccountModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model.output,error);
    }];
}


//1开启 0关闭
+(void)getFinancialStatusWithCompletionHandle:(void (^)(NSInteger, NSError *))complete{
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kFinancialStatus]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    NSInteger status = 0;
    @try {
        status = [responseObj[@"output"][@"status"] integerValue];
        if (responseObj[@"error_code"] == 0) {
            error = [self createError:responseObj[@"error_msg"]];
        }
    } @catch (NSException *e) {
        //                    NSLog(@"Unarchive of %@ failed: %@", key, e);
    } @finally {
        complete(status,error);
    }
}];
}

+(void)signWithUserid:(NSString *)userid andSession:(NSString *)session andCompletionHandle:(void (^)(AccountModel *, NSError *))complete{
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,ksign]
    parameters:[NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session]
completionHandler:^(id responseObj, NSError *error) {
    PCAccountModel *model = [PCAccountModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model.output,error);
}];
}


+(void)setMarketingCodeWithUserid:(NSString *)userid andSession:(NSString *)session andCode:(NSString *)code andCompletionHandle:(void (^)(MarketingCodeModel *, NSError *))complete{
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kSetMarketingCode]
           parameters:[NSString stringWithFormat:@"userid=%@&sessionid=%@&spread_num=%@",userid,session,code]
    completionHandler:^(id responseObj, NSError *error) {
        PCMarketingCodeModel *model = [PCMarketingCodeModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model.output,error);
    }];
}



//+(void)getMarketingCodeWithUserid:(NSString *)userid andSession:(NSString *)session andCompletionHandle:(void (^)(MarketingCodeModel *, NSError *))complete{



+ (void)getPointsRankListWithCompletionHandle:(void (^)(PCPointsListModel *, NSError *))complete{
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetRecommendRankList]
           parameters:nil
    completionHandler:^(id responseObj, NSError *error) {
        PCPointsListModel *model = [PCPointsListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}


+(void)getPointsLatestListWithCompletionHandle:(void (^)(PCPointsListModel *, NSError *))complete{
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetRecommendLatestList]
           parameters:nil
    completionHandler:^(id responseObj, NSError *error) {
        PCPointsListModel *model = [PCPointsListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}



+(void)getTuiguangImageWithCompletionHandle:(void (^)(PCTuiguangModel *, NSError *))complete{
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetTuiguangImage]
    parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    PCTuiguangModel *model = [PCTuiguangModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error);
}];
}


+(void)getTuiguangInfoWithUserid:(NSString *)userid andSession:(NSString *)session andCompletionHandle:(void (^)(MarketingCodeModel *, NSError *))complete{
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetMarketingCode]
           parameters:[NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session]
    completionHandler:^(id responseObj, NSError *error) {
        PCMarketingCodeModel *model = [PCMarketingCodeModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model.output,error);
    }];
}

+(void)getTuiguangListWithUserid:(NSString *)userid andSession:(NSString *)session andCompletionHandle:(void (^)(PCTuiguangListModel *model, NSError *error))complete{
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetMyRecommendList]
           parameters:[NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session]
    completionHandler:^(id responseObj, NSError *error) {
        PCTuiguangListModel *model = [PCTuiguangListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}


+(void)modifyNickNameWithUserid:(NSString *)userid andSession:(NSString *)session andNickname:(NSString *)nickname andCompletionHandle:(void (^)(AccountModel *model, NSError *))complete{
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kModifyNickName]
           parameters:[NSString stringWithFormat:@"userid=%@&sessionid=%@&nickname=%@",userid,session,nickname]
    completionHandler:^(id responseObj, NSError *error) {
        PCAccountModel *model = [PCAccountModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model.output,error);
    }];
}












@end












